package com.haixiaoke.saas.enterprise.workOrder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.workOrder.domain.WorkOrderRecord;
import com.haixiaoke.saas.workOrder.service.IWorkOrderRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 工单跟进记录Controller
 *
 * @author qixi
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/enterprise/workOrder/record")
public class EnterpriseWorkOrderRecordController extends BaseController {
    @Autowired
    private IWorkOrderRecordService workOrderRecordService;

    /**
     * 查询工单跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderRecord workOrderRecord) {
        startPage();
        List<WorkOrderRecord> list = workOrderRecordService.selectWorkOrderRecordList(workOrderRecord);
        return getDataTable(list);
    }

    /**
     * 导出工单跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderRecord:export')")
    @Log(title = "工单跟进记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkOrderRecord workOrderRecord) {
        List<WorkOrderRecord> list = workOrderRecordService.selectWorkOrderRecordList(workOrderRecord);
        ExcelUtil<WorkOrderRecord> util = new ExcelUtil<WorkOrderRecord>(WorkOrderRecord.class);
        util.exportExcel(response, list, "工单跟进记录数据");
    }

    /**
     * 获取工单跟进记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId) {
        return success(workOrderRecordService.selectWorkOrderRecordByRecordId(recordId));
    }

    /**
     * 新增工单跟进记录
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderRecord:add')")
    @Log(title = "工单跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrderRecord workOrderRecord) {
        return toAjax(workOrderRecordService.insertWorkOrderRecord(workOrderRecord));
    }

    /**
     * 修改工单跟进记录
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderRecord:edit')")
    @Log(title = "工单跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderRecord workOrderRecord) {
        return toAjax(workOrderRecordService.updateWorkOrderRecord(workOrderRecord));
    }

    /**
     * 删除工单跟进记录
     */
    @PreAuthorize("@ss.hasPermi('business:workOrderRecord:remove')")
    @Log(title = "工单跟进记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds) {
        return toAjax(workOrderRecordService.deleteWorkOrderRecordByRecordIds(recordIds));
    }
}
